<?php
include_once 'connection/connection_database.php';
include_once 'app/model/tags/process.php';
include_once 'app/model/page/process.php';
include_once 'app/function/xulychuoi.php';

$pages = new Pages();
$tags = new Tags();
//page
$tag_name = mysql_fetch_array($tags->FindByTagName($_GET["tag"]));
$pageByTitle = $pages->FillByPageTags($tag_name["tag_name"]);
$i = 0;
$numPage = 5;
if (!$_GET["page"]) {
    $page = 1;
} else if ((int) $_GET["page"]) {
    $page = $_GET["page"];
}
$sodu = mysql_num_rows($pageByTitle);

$sotrang = ceil($sodu / $numPage);
$pageCurrent = (($page * $numPage) - $numPage);
$sql = "SELECT * FROM cate_board_page WHERE page_tag LIKE '%{$tag_name["tag_name"]}%' and page_status = 1 ORDER BY page_id ASC LIMIT {$pageCurrent},{$numPage}";

$resultPaging = mysql_query($sql);
?>
<div id="about_company">
	<?php
		//Tạo hiệu ứng sau mỗi lần refresh trình duyệt bức ảnh quảng cáo sẽ thay đổi
		//Mảng chứa tên các bức ảnh
		$images = array("banner_top" => "banner_top", "banner_top2" => "banner_top2");
		//Biến lưu tên ảnh được lấy ngẫu nhiên từ mảng
		$randImages = array_rand($images);
	?>            						
    <img width="710" height="150" src="<?php echo $url["home"] ?>/images/upload/<?php echo $randImages ?>.gif">            						
    <div class="duong_dan">
        <a href="<?php echo $url["home"] ?>/index.html"><img src="<?php echo $url["home"] ?>/images/icon-home.png" />  Trang chủ </a>
        <hr width="100%" size="1" color="#CCCCCC"/>
    </div><!-- End .duong_dan-->
    <div id="noi_dung_bai_viet">
        <div class="noi_dung_chinh">
            <h2><img src="<?php echo $url["home"] ?>/images/icon-category.png" />  Các kết quả với Tags : <?php echo $_GET["tag"]; ?></h2>
            <hr width="100%" size="1" color="#CCCCCC"/>
            <div class="ds_bai_theo_cmuc">
                <?php while($rowPage = mysql_fetch_array($resultPaging)) : ?>
                <div class="article">
                    <h2><img src="<?php echo $url["home"] ?>/images/article-1.png" /><a href="<?php echo $url['home'] .'/' . $rowPage["page_link"].".html" ?>" title="<?php echo $rowPage["page_title"] ?>"><?php echo $rowPage["page_title"] ?></a>
                    <span class="counter_view">Có <?php echo $rowPage["page_counter"] ?> lượt xem</span>
                    </h2>
                    <a href="<?php echo $url['home'] .'/' . $rowPage["page_link"].".html" ?>" title="<?php echo $rowPage["page_title"] ?>"><img src="<?php echo $rowPage["page_image"] ?>" alt="<?php echo $rowPage["page_title"] ?>" align="left" width="432" height="309"/></a>
                    <p class="some_text">
                        <?php echo $rowPage["page_summary"] ?>...<br />
                        <a href="<?php echo $url['home'] .'/' . $rowPage["page_link"].".html" ?>">Chi tiết...</a>
                    </p>
                    <p class="tags">	
                        <img src="<?php echo $url["home"] ?>/images/tags-1.png" />
                        <?php 
                            $tags = explode(",",$rowPage["page_tag"]);
                            foreach ($tags as $_tags) {
							$_tags = trim(khongdau($_tags));
							$link_tags = strtolower(preg_replace('/[^a-z0-9]+/i','-',$_tags));	
                        ?>
                        <a href="<?php echo $url["home"] ?>/tag/<?php echo $link_tags; ?>"> - <?php echo $_tags; ?></a>
                        <?php } ?>
                    </p>
                    <div class="comments like share">
                        <!-- AddThis Button BEGIN -->
                        <div class="addthis_toolbox addthis_default_style ">
                        <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                        <a class="addthis_button_tweet"></a>
                        <a class="addthis_button_pinterest_pinit"></a>
                        <a class="addthis_counter addthis_pill_style"></a>
                        </div>
                        <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-50fdf6e91b97493b"></script>
                        <!-- AddThis Button END -->
                    </div><!--End .comments-->
                </div><!--End article-->
                <?php endwhile; ?>
            </div><!--End ds_bai_theo_cmuc-->
            <div id="paginate">
            	<ul class="nav">
                <?php
                    for ($i = 1; $i <= $sotrang; $i++) {
                        if ($page == $i) {
                            echo "<li><a href='javascript: void(0)'> [ {$i} ] </a></li>";
                        } else {
                            echo "<li><a href='{$url["home"]}/tag/{$_GET["tag"]}/p/{$i}'> [ {$i} ] </a></li>";
                        }
                    }
                ?>
                </ul>
            </div>
        </div><!-- End #danh_sach_comment-->
        <div class="clear"></div><!-- End .clear-->
    </div><!--End #noi_dung_chinh-->
</div>